//TOCMAT重启之后 点击左侧列表跳转登录首页 
if (window != top) {
	top.location.href = location.href;
}
$(document).ready(function() {
	changeCode();
	$("#codeImg").bind("click", changeCode);
});

$(document).keyup(function(event) {
	if (event.keyCode == 13) {
		$("#submitlogin").trigger("click");
	}
});

function genTimestamp() {
	var time = new Date();
	return time.getTime();
}

function changeCode() {
	$("#codeImg").attr("src", ctxf + "/fantasy/user/code?t=" + genTimestamp());
}
function checkInput() {
	var loginname = $("#username").val();
	var password = $("#password").val();
	var inputCode =  $("#inputCode").val();
	if (loginname=="") {
		 $("#errorinfo").html("用户名不能为空！");
		 return false;
	}
	if (password=="") {
		 $("#errorinfo").html("密码不能为空！");
		 return false;
	}
	if (inputCode=="") {
		 $("#errorinfo").html("验证码不能为空！");
		 return false;
	}
	return true;
}
function login(){
	if(checkInput()){		
		var username = $("#username").val();
		var password = $("#password").val();
		var inputCode =  $("#inputCode").val();;
		$.ajax({
			type: "POST",
			url: ctxf + '/fantasy/user/login',
	    	data: {username:username,password:password,inputcode:inputCode,tm:new Date().getTime()},
			dataType:'json',
			cache: false,
			success: function(data){
				if("success" == data.result){
					if (data.logintype == 1) {
						window.location.href=ctxf + "/fantasy/move/tohome";
					} else if (data.logintype == 2) {
						window.location.href=ctxf + "/a";
					}
				}else if("null" == data.result){
					 $("#errorinfo").html("用户名和密码不能为空！");
				}else if("specialchar" == data.result){
					 $("#errorinfo").html("用户名不能包含特殊字符！");
					 changeCode();
				}else if("pwderror" == data.result){
					 $("#errorinfo").html("用户名或密码错误！");
					 changeCode();
				}else if("statuserror" == data.result){
					 $("#errorinfo").html("用户已被禁用！");
					 changeCode();
				}else if("nullcode" == data.result){
					 $("#errorinfo").html("验证码为空或错误!");
					 changeCode();
				}else if("loginTimeerror" == data.result){
					var id = data.operatorId;
					parent.layer.open({
						type: 2,
						area: [800+'px', 350+'px'],
						fix: false, //不固定
						shade:0.4,
						title:"强制修改密码",
						content: "sysOperator/toMonthEditPassword?id="+id+"&type="+2
					});
				}
				
				else{
					 $("#errorinfo").html("网络异常，请重新尝试!");
					 changeCode();
				}
			}
		});
	}
}

